package com.example.miniappssm.controller;

import com.example.miniappssm.bean.Cart;
import com.example.miniappssm.bean.Goods;
import com.example.miniappssm.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
public class CartController {

    @Autowired
    CartService cartService;

    @RequestMapping("/showCart")
    public List<Goods> showCart(@RequestParam("userId") Integer userId) {
        return cartService.showAllGoodsFromUserIdInCart(userId);
    }

    @RequestMapping("/addCart")
    public void addCart(Cart cart) {
        cartService.addGoodsInCart(cart);
    }

    @RequestMapping("/removeCart")
    public void removeCart(@RequestParam("cartId") Integer cartId) {
        cartService.removeGoodsFromCartByCartId(cartId);
    }
}
